<html>
	<head>
	    <title>Letta Teknoloji Yonetim Paneli</title>
		<?php
			include_once("config.php");
		?>
		<meta content="text/html; charset=utf-8" http-equiv="content-type" />
		<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
		<script type="text/javascript" src="js/ckeditor/ckeditor.js"></script>
		<script type="text/javascript" src="js/ckeditor/adapters/jquery.js"></script>
		<script type="text/javascript" src="http://ckeditor.com/apps/ckeditor/3.6.2/lang/tr.js?t=B8DJ5M3"></script>
		<script src="js/ckeditor/sample.js" type="text/javascript"></script>
		<link href="css/sample.css" rel="stylesheet" type="text/css" />
		<link type="text/css" href="css/ui/jquery-ui-1.8.16.custom.css" rel="stylesheet" />	
		<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
		<script type="text/javascript">	
		function load(indeks,edit)
		{
		    var loadData = "stage="+indeks+"&id="+edit;
			$.ajax({url:"select.php",
				  data:loadData,
				  success:function(data)
				  {
				     editLoad(data,indeks);
				  },
				  dataType:"json"	
				});		
		}
		function editLoad(data,indeks)
		{		if(indeks == 1)
				{
						$("#icerikBaslik").val(data[1]);
						$("#icerikAciklama").val(data[2]);
						$("#resimEdit").text(data[3]);
						$("#kresimEdit").text(data[4]);
						$("#editor1").val(data[5]);			
						$("#comboEdit").text(data[10]);
						$("#comboHidden").text(data[6]);
				}
				if(indeks == 2)
				{
					$("#icerikBaslik").val(data[1]);
					$("#icerikAciklama").val(data[2]);
					$("#editor1").val(data[4]);
					$("#resimEdit").text(data[3]);
				}
		}
		//<![CDATA[
			$(function()
			{
				var config = {
					toolbar:
					[
						['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink','Source'],
						['UIColor']
					],
					language: 'tr'
				};
				// Initialize the editor.
				// Callback function can be passed and executed after full instance creation.
				$('.jquery_ckeditor').ckeditor(config);
			});
		//]]>
		</script>
		<script type="text/javascript">
			var ustID = 0;
			$(function(){
				$('#tabs').tabs();
            });
			function init(data)
			{
				section(data);
			}
			
			function kaydet(giris)
			{
				ustID = $('select[name=combobox] option:selected').val();
				$datas = "editor1="+$("#editor1").val()
				+"&icerikBaslik="+$("#icerikBaslik").val()
				+"&icerikAciklama="+$("#icerikAciklama").val()
				+"&icerikResim="+$("#icerikResim").val()
				+"&sayfa="+giris
				+"&ust="+ustID
				+"&kucukResim="+$("#kucukResim").val();
				$.post("veriEkle2.php",$datas,
					function(data)
					{
						if(data.length == 0)
						{
							 alert("Basaryla Kaydettinz!");
							 $("#resimForm").submit();
						}
					}
				);
			}
		</script>
		<script type="text/javascript">
		    var veri = "0";
			
		    function sayfaSecim(index)
			{
                window.location = "index.php?stage="+index;
			}
			$(function() {
				$( "#anasayfa").button({
				});
				$( "#sayfalar").button({
				});
				$( "#urunler").button({
				});
				$( "#haberler").button({
				});
				$( "#ayarlar").button({
				});
				$( "#cikis").button({
				});
				$( "#insert" )
				.button({
					icons: {
					primary: "ui-icon-plus"
					},
					text: true,
			    })
				.click(function(){
				    section(1);
				});
				$( "#list" ).button({
					icons: {
					primary: "ui-icon-note"
					},
					text: true
			    })
				.click(function(){
				    section(0);
				});
				$( "#kaydet" ).button({
					icons: {
					primary: "ui-icon-disk"
					},
					text: true
			    });
			});
			function section(data)
			{
				if(data == 0)
				{
					$("#listeTema").css("visibility","hidden");
					$("#tema").css("visibility","visible");
					
				}
				if(data == 1)
				{
					$("#listeTema").css("visibility","visible");
					$("#tema").css("visibility","hidden");
					
				}
			}
			function duzenle(giris,edit)
			{
				ustID = $('select[name=ust] option:selected').val();
				if($("#comboEdit").css("display") == 'inline')
				{
					ustID = 0;
				}
			    if($("#kucukResim").val() == "")
				{
					$datas = "editor1="+$("#editor1").val()
					+"&icerikBaslik="+$("#icerikBaslik").val()
					+"&icerikAciklama="+replaceAmp($("#icerikAciklama").val())
					+"&icerikResim="+$("#icerikResim").val()
					+"&sayfa="+giris
					+"&ust="+ustID
					+"&edit="+edit;
				}
				else if($("#icerikResim").val() == "")
				{
					$datas = "editor1="+replaceAmp($("#editor1").val())
					+"&icerikBaslik="+$("#icerikBaslik").val()
					+"&icerikAciklama="+replaceAmp($("#icerikAciklama").val())
					+"&sayfa="+giris
					+"&ust="+ustID
					+"&kucukResim="+$("#kucukResim").val()
					+"&edit="+edit;
				}
				else
				{
					$datas = "editor1="+replaceAmp($("#editor1").val())
					+"&icerikBaslik="+$("#icerikBaslik").val()
					+"&icerikAciklama="+replaceAmp($("#icerikAciklama").val())
					+"&icerikResim="+$("#icerikResim").val()
					+"&sayfa="+giris
					+"&ust="+ustID
					+"&kucukResim="+$("#kucukResim").val()
					+"&edit="+edit;
				}
				function replaceAmp(str)
                {
				   return str.replace(/&/g, "%26");
				}
				$.post("guncelle.php",$datas,
					function(data)
					{
						if(data.length == 0)
						{
							 alert("Basaryla Guncellediniz!");
							 $("#resimForm").submit();
						}
					}
				);
			}
			function resimVazgec(data)
			{
				if(data == 1)
				{
					$("#icerikResim").show('slow');
					$("#close1").hide();
					$("#resimEdit").hide();					
				}
				if(data == 2)
				{
					$("#close2").hide();
					$("#kucukResim").show('slow');
					$("#kresimEdit").hide();	
				}
				if(data == 3)
				{
					$("#close3").hide();
					$("#combobox").show('slow');
					$("#comboEdit").hide();	
				}
			
				
			}
	    </script>

        <style type="text/css">
			body{ font: 62.5% "Trebuchet MS", sans-serif; margin: 50px;}
			.demoHeaders { margin-top: 2em; }
			#dialog_link {padding: .4em 1em .4em 20px;text-decoration: none;position: relative;}
			#dialog_link span.ui-icon {margin: 0 5px 0 0;position: absolute;left: .2em;top: 50%;margin-top: -8px;}
			ul#icons {margin: 0; padding: 0;}
			ul#icons li {margin: 2px; position: relative; padding: 4px 0; cursor: pointer; float: left;  list-style: none;}
			ul#icons span.ui-icon {float: left; margin: 0 4px;}
			.demo{top:20px;position:absolute;}
			#toolbar {padding: 10px 4px;}
			#tabs{width:65%;position:absolute;top:20%}
			#insert{margin-left:55%;}
			#baslik{position:absolute;margin-top:2px;margin-bottom:2px;}
			#sag-menu{position:absolute;margin-left:67%;top:20%;width:20%;height:50%;}
			.sutun1{width:150px;}
			.girisler{width:800px;}
			div#users-contain { width: 1050px; margin: 20px 0; }
			div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
			div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
            label, input { display:block; }
			fieldset { padding:0; border:0; margin-top:25px; }
			.konuBaslik{margin-top:-5px;}
			h1{margin-top:-50px;}
			#icerikResim{display:none;}
			#kucukResim{display:none;}
			#thumb{display:none;}
			#contentImage{display:none;}
			#ust2{display:none;}
			.close{margin-left:5px;}
			#combobox{display:none;width:150px;margin-right:-30px;}
		</style>
	</head>
	
	<?php 
	    $loadIndex = $_GET['stage'];
		$loadedit  = $_GET['edit'];
		echo "<body onLoad=\"load(".$loadIndex.",".$loadedit.");\">";
    ?>

    <div class="demo">
		<span id="toolbar" class="ui-widget-header ui-corner-all">
			<a href="index.php"><button id="anasayfa">AnaSayfa</button></a>
			<button id="sayfalar" onClick="sayfaSecim(1);">Sayfalar</button>
			<button id="haberler" onClick="sayfaSecim(2);">Haberler</button>
			<button id="cikis">Cikis</button>
		</span>
    </div>
	<hr/>
	<?php
	    
		$sayfaBilgi = array(
							array("sayfaAdi"=>"sayfa","sayfaEkleme"=>"Sayfa Ekle","sayfaListeleme"=>"Sayfa Listesi"),
							array("sayfaAdi"=>"haber","sayfaEkleme"=>"Haber Ekle","sayfaListeleme"=>"Haber Listesi")
							);
	    $turler = array("anasayfa","veri","haber");
        if(!empty($_GET['stage']))
	    {
		    $indeks = $_GET['stage'];
			echo "<div id=\"insert\">";
				echo "<a href=\"?stage=".$indeks."&section=0\"><span id=\"insertLabel\">".$sayfaBilgi[$indeks-1]["sayfaEkleme"]."</span></a>";
			echo "</div>";
			echo "<div id=\"list\">";
				echo "<a href=\"?stage=".$indeks."&section=1\"><span id=\"listLabel\">".$sayfaBilgi[$indeks-1]["sayfaListeleme"]."</span></a>";
			echo "</div>";
			
		}
	    echo "<div id=\"tema\">";
		echo "<h1 class=\"konuBaslik\">".$sayfaBilgi[$indeks-1]["sayfaEkleme"]."</h1>";
		
		?>		
		<div id="tabs">
				
				<div id="tabs-1">
						<table class="girisler">

							<tr>
								<td class="sutun1" id="baslikEtiketi">Baslik</td>
								<td><input type="text" name="icerikBaslik" id="icerikBaslik" style="width:65%;"></input></td>
									<?php
									    if($_GET['stage'] == 1 )
										{
										    $edit         = @$_GET['edit'];
											$queryString  = "SELECT * FROM veri WHERE aktif=1 AND ustid !=-1 AND id!=$edit";
											$komut = mysql_query($queryString) or die(mysql_error());
											echo "<td>
												<select id=\"combobox\" name=\"ust\">"; 
												while($value = mysql_fetch_array($komut))
												{
													echo "<option value=\"$value[0]\">".$value[1]."</option>";
												}
											echo "</select> 
											<span id=\"comboEdit\"></span><img src=\"image/close.gif\" onClick=\"resimVazgec(3);\" id=\"close3\" class=\"close\"/>
											<span id=\"comboHidden\" style=\"display:none;\"></span>
										   </td>";
										}	
									?>
									
							</tr>

							<tr>	
								<td class="sutun1" id="resimEtiketi">Resim</td>
				                <td>
					<form id="resimForm" action=<?php echo "index.php?stage=".$_GET['stage']."&section=1";?> enctype="multipart/form-data" method="post">
								<input type="file" name="icerikResim" id="icerikResim"></input>
								<span id="resimEdit"></span><img src="image/close.gif" onClick="resimVazgec(1);" id="close1"  class="close"/>
								<div>
								<?php
								 if(isset($_FILES['icerikResim']['name']))
								 {
									$dosya  = basename($_FILES['icerikResim']['name']);
									$dosya2 = basename($_FILES['kucukResim']['name']);
									
									move_uploaded_file($_FILES['icerikResim']['tmp_name'], '../lettayeni/image/' . $dosya);
									move_uploaded_file($_FILES['kucukResim']['tmp_name'], '../lettayeni/image/' . $dosya2);
								 }
								 if(isset($_FILES['contentImage']['name']))
								 {
									$file  = basename($_FILES['contentImage']['name']);
									$file2 = basename($_FILES['thumb']['name']);
									
									move_uploaded_file($_FILES['contentImage']['tmp_name'], '../lettayeni/image/' . $file);
									move_uploaded_file($_FILES['thumb']['tmp_name'], '../lettayeni/image/' . $file2);
								 }
								?>
								</div>
								</td>
							</tr>
							<tr>
								<td class="sutun1" id="kucukEtiket">Kucuk Resim</td>
								<td>
									<input type="file" id="kucukResim" name="kucukResim" />
									<span id="kresimEdit"></span><img src="image/close.gif" onClick="resimVazgec(2);" id="close2"  class="close"/>
								</td>
							</tr>
						</table>
						<p>Kisa Metin:</p>
						<textarea class="jquery_ckeditor" cols="150" id="icerikAciklama" name="icerikAciklama" rows="10"></textarea>
						<p>Tam Metin:</p>
						<textarea class="jquery_ckeditor" cols="150" id="editor1" name="editor1" rows="10"></textarea>
						
				</div>

             </form>
			</div>

		<div id="sag-menu"  class= "ui-widget-content ui-corner-all">
			<div class="ui-widget-header ui-corner-all" style="margin-top:1px;">&nbsp;<br/>&nbsp;</div><br/>
			<span style="font-size:12;margin-left:5px;">Icerigi Guncelle:</span><button id="kaydet" style="margin-left:15px" onClick="duzenle(<?php
			echo $_GET['stage'].",".$_GET['edit'];
			?>);">Guncelle</button>
			<br>
		</div>
    </div>
 </html>